package com.zcdyy.rentalofhouse.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcdyy.rentalofhouse.R;
import com.zcdyy.rentalofhouse.bean.AllRental;
import com.zcdyy.rentalofhouse.bean.ShopRent;
import com.zcdyy.rentalofhouse.utils.BaseTranslucentActivity;
import com.zcdyy.rentalofhouse.utils.ImageLoaderUtils;

public class ShopsDetailActivity extends BaseTranslucentActivity implements View.OnClickListener {
    private TextView tvTitle;
    private ImageView ivHousePic;
    private TextView tvHouseName;
    private TextView tvHouseMoney;
    private TextView tvLeiXing;
    private TextView tvMianJi;
    private TextView tvQuYu;
    private TextView tvDiDuan;
    private TextView tvZuJin;
    private TextView tvHouseDesc;
    private TextView tvLianXiRen;
    private TextView tvShouJiHao;
    private LinearLayout ll_phone;
    private LinearLayout ll_sms;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shops_detail);

        initView();
        initData();
        initTitle();
        bind();
    }

    private void bind() {
        ll_phone.setOnClickListener(this);
        ll_sms.setOnClickListener(this);
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getBundleExtra("bundle");
            tvTitle.setText("商铺详情");
            ShopRent shopRent = (ShopRent) bundle.getSerializable("allshop");
            ImageLoaderUtils.loadImage(this, shopRent.getPic().getFileUrl(), ivHousePic);
            tvHouseName.setText(shopRent.getBiaoTi());
            tvHouseMoney.setText(shopRent.getShouJia());
            tvLeiXing.setText(shopRent.getLeiXing());
            tvMianJi.setText(shopRent.getMianJi());
            tvQuYu.setText(shopRent.getQuYu());
            tvDiDuan.setText(shopRent.getDiDuan());
            tvZuJin.setText(shopRent.getShouJia());
            tvHouseDesc.setText(shopRent.getMiaoShu());
            tvLianXiRen.setText(shopRent.getLianXiRen());
            tvShouJiHao.setText(shopRent.getShouJiHao());
        }
    }

    private void initView() {
        ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        ll_sms = (LinearLayout) findViewById(R.id.ll_sms);
        tvTitle = (TextView) findViewById(R.id.top_tv_title);
        ivHousePic = (ImageView) findViewById(R.id.iv_house_pic);
        tvHouseName = (TextView) findViewById(R.id.tv_house_name);
        tvHouseMoney = (TextView) findViewById(R.id.tv_house_money);
        tvLeiXing = (TextView) findViewById(R.id.tv_tingshi_show);
        tvMianJi = (TextView) findViewById(R.id.tv_house_mianji_show);
        tvQuYu = (TextView) findViewById(R.id.tv_house_zhuangxiu_show);
        tvDiDuan = (TextView) findViewById(R.id.tv_house_louceng);
        tvZuJin = (TextView) findViewById(R.id.tv_house_louceng_show);
        tvHouseDesc = (TextView) findViewById(R.id.tv_house_desc);
        tvLianXiRen = (TextView) findViewById(R.id.tv_lianxiren);
        tvShouJiHao = (TextView) findViewById(R.id.tv_shoujihao);
    }

    private void initTitle() {
        tvTitle.setText("商铺详情");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.ll_phone:
                Intent intent = new Intent();
                intent.setAction("android.intent.action.CALL");
                intent.setData(Uri.parse("tel:"+ tvLianXiRen.getText().toString()));//mobile为你要拨打的电话号码，模拟器中为模拟器编号也可
                startActivity(intent);

                break;
            case  R.id.ll_sms:
                Uri smsToUri = Uri.parse("smsto:"+tvLianXiRen.getText().toString());
                Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
                mIntent.putExtra("sms_body", "您好，我对你的房屋很感兴趣。方便联系一下么？");
                startActivity( mIntent );
                break;
        }
    }
}
